From: Brad Jorsch Date: Mon, 12 Nov 2012 05:42:26 +0000 (-0800) Subject: (bug 41990) Fix regression in API edit of redirect X-Git-Tag: 1.31.0-rc.0~21656 X-Git-Url: http://git.cyclocoop.org/%7D%7Cconcat%7B?a=commitdiff_plain;h=f6e8d4a04c1e661045498d6e6cb97e1625ef8967;p=lhc%2Fweb%2Fwiklou.git (bug 41990) Fix regression in API edit of redirect Before ContentHandler, an API edit passing a redirect for title and redirect=true and omitting basetimestamp would use the last revision timestamp of the target page. When ContentHandler was merged, this was accidentally changed to use the last revision timestamp of the redirect page, which was likely much earlier than the target page's last revision and so causes an edit conflict in almost all cases. Some scripts took advantage of this along with appendtext to add notices to users' talk pages, so restore that old behavior. We'll also adjust the contentmodel/contentformat detection added by ContentHandler to use the model and format of the target page rather than the redirect in this case, as that seems more likely to be less wrong. Change-Id: If0c674e26a4deb54ec14f0bf45418d666a397347 --- diff --git a/RELEASE-NOTES-1.21 b/RELEASE-NOTES-1.21 index 923df754f4..16d842bc1b 100644 --- a/RELEASE-NOTES-1.21 +++ b/RELEASE-NOTES-1.21 @@ -63,6 +63,8 @@ production. * (bug 41899) A PHP notice no longer occurs when using the "rvcontinue" API parameter. * (bug 42036) Account creation emails now contain canonical (not protocol-relative) URLs. +* (bug 41990) Fix regression: API edit with redirect=true and lacking + starttimestamp and basetimestamp should not cause an edit conflict. === API changes in 1.21 === * prop=revisions can now report the contentmodel and contentformat, see docs/contenthandler.txt diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php index 4cb91bc9e8..81b3ef2fcb 100644 --- a/includes/api/ApiEditPage.php +++ b/includes/api/ApiEditPage.php @@ -54,28 +54,6 @@ class ApiEditPage extends ApiBase { $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) ); } - if ( !isset( $params['contentmodel'] ) || $params['contentmodel'] == '' ) { - $contentHandler = $pageObj->getContentHandler(); - } else { - $contentHandler = ContentHandler::getForModelID( $params['contentmodel'] ); - } - - // @todo ask handler whether direct editing is supported at all! make allowFlatEdit() method or some such - - if ( !isset( $params['contentformat'] ) || $params['contentformat'] == '' ) { - $params['contentformat'] = $contentHandler->getDefaultFormat(); - } - - $contentFormat = $params['contentformat']; - - if ( !$contentHandler->isSupportedFormat( $contentFormat ) ) { - $name = $titleObj->getPrefixedDBkey(); - $model = $contentHandler->getModelID(); - - $this->dieUsage( "The requested format $contentFormat is not supported for content model ". - " $model used by $name", 'badformat' ); - } - $apiResult = $this->getResult(); if ( $params['redirect'] ) { @@ -104,9 +82,34 @@ class ApiEditPage extends ApiBase { $apiResult->setIndexedTagName( $redirValues, 'r' ); $apiResult->addValue( null, 'redirects', $redirValues ); + + // Since the page changed, update $pageObj + $pageObj = WikiPage::factory( $titleObj ); } } + if ( !isset( $params['contentmodel'] ) || $params['contentmodel'] == '' ) { + $contentHandler = $pageObj->getContentHandler(); + } else { + $contentHandler = ContentHandler::getForModelID( $params['contentmodel'] ); + } + + // @todo ask handler whether direct editing is supported at all! make allowFlatEdit() method or some such + + if ( !isset( $params['contentformat'] ) || $params['contentformat'] == '' ) { + $params['contentformat'] = $contentHandler->getDefaultFormat(); + } + + $contentFormat = $params['contentformat']; + + if ( !$contentHandler->isSupportedFormat( $contentFormat ) ) { + $name = $titleObj->getPrefixedDBkey(); + $model = $contentHandler->getModelID(); + + $this->dieUsage( "The requested format $contentFormat is not supported for content model ". + " $model used by $name", 'badformat' ); + } + if ( $params['createonly'] && $titleObj->exists() ) { $this->dieUsageMsg( 'createonly-exists' ); }